.assistant {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: $white;
  overflow: hidden;
  border-left: 1px solid $palette-neutral-400;
}

.assistant__header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid $palette-neutral-200;
  flex-shrink: 0;
  height: 51px;
  gap: 12px;
}

%scrollbar-thin {
  scrollbar-gutter: stable;

  // Make scrollbar thin
  scrollbar-width: thin; // Firefox

  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
  }
}

.assistant__content {
  @extend %scrollbar-thin;

  flex: 1;
  padding: 20px 11px 0 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-gutter: stable;
}

.assistant__header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.assistant__header-separator {
  width: 1px;
  height: 16px;
  background-color: $palette-neutral-200;
}

.assistant__header-icon {
  font-size: 16px;
  color: $palette-neutral-700;

  &:hover {
    color: $palette-neutral-1200;
  }
}

.assistant__title {
  @extend %ellipsis;

  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  flex: 1;

  i {
    margin-right: 10px;
    color: $palette-blue-500;
  }
}

.assistant__welcome {
  flex: 0 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px;
}

.assistant__welcome-kuma {
  position: relative;
  display: block;
  width: 80px;
  height: 94px;
  margin: 0 auto 18px;

  &::after {
    content: '';
    width: 24px;
    height: 6px;
    background-color: $palette-neutral-100;
    border-radius: 100%;
    transform: translateX(-50%);

    @include absolute(auto, auto, 0, 50%);
  }
}

.assistant__welcome-video {
  display: block;
  width: 80px;
  height: 80px;
  outline: 0;
  margin: 0 auto;
}

.assistant__welcome-title {
  font-size: 20px;
  font-weight: 600;
  color: $palette-neutral-1300;
  margin: 0 0 12px;
}

.assistant__welcome-subtitle {
  font-size: 13px;
  color: $palette-neutral-900;
  line-height: 1.5;
  margin: 0 0 32px;
}

.assistant__welcome-title-greeting {
  color: $palette-neutral-700;
}

.assistant__suggestions {
  padding-bottom: 12px;
}

.assistant__suggestion {
  display: flex;
  gap: 18px;
  border: solid 1px $palette-neutral-200;
  padding: 14px 18px;
  text-align: left;
  width: 100%;
  margin-bottom: 12px;

  @include rounded($rounded-xl);
  @include elevation($elevation-low);

  &:hover {
    text-decoration: none;
    border-color: $palette-neutral-400;
  }
}

.assistant__suggestion-icon-wrapper {
  flex: 0 0 40px;
}

.assistant__suggestion-icon {
  width: 40px;
  height: 40px;
  line-height: 40px;
  border-radius: 100%;
  background-color: $palette-neutral-50;
  color: $palette-neutral-700;
  text-align: center;
}

.assistant__suggestion-text {
  min-width: 0;
}

.assistant__suggestion-title {
  @extend %ellipsis;

  font-size: 13px;
  font-weight: 500;
  line-height: 20px;
  margin-bottom: 4px;
  color: $palette-neutral-1200;
}

.assistant__suggestion-description {
  @extend %ellipsis;

  font-size: 12px;
  line-height: 20px;
  color: $palette-neutral-900;
}

.assistant__input {
  padding: 20px;
  padding-top: 8px;
  flex-shrink: 0;
}

.assistant__input-status-icon {
  color: $palette-blue-500;
  font-size: 14px;
}

.assistant__input-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 400;
  line-height: 20px;
  border-radius: 12px 12px 0 0;
  background: $palette-neutral-25;
  color: $palette-neutral-900;

  &.is-running {
    color: #16829c;
    background-color: $palette-cyan-50;
  }
}

.assistant__status-message {
  @extend %ellipsis;

  display: inline-block;
}

.assistant__input-section {
  background: $palette-neutral-25;

  &.is-running {
    background-color: $palette-cyan-50;
  }
}

.assistant__input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: $white;
  border: 1px solid $palette-neutral-500;
  transition: all 0.2s;
  padding-bottom: 12px;

  @include rounded($rounded-md);
  @include elevation($elevation-low);

  &.has-context {
    padding-top: 36px;
  }
}

.assistant__input-textarea {
  @extend %scrollbar-thin;

  flex: 1;
  border: none;
  resize: none;
  background: transparent;
  font-size: 13px;
  line-height: 20px;
  max-height: 120px;
  outline: none;
  box-shadow: none;
  padding: 8px 50px 0 16px;

  &:focus {
    outline: none;
    box-shadow: none;
  }

  &::placeholder {
    color: $palette-neutral-600;
  }
}

.assistant__context-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 8px;
  background: $palette-neutral-100;
  border-radius: 16px;
  font-size: 10px;
  color: $palette-neutral-900;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 5px;
}

.assistant__context-text {
  @extend %ellipsis;

  font-weight: 500;
  letter-spacing: 0.2px;
}

.assistant__send-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: $palette-neutral-1200;
  color: $white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;

  i {
    font-size: 14px;
  }

  &:hover:not(.assistant__send-button--disabled) {
    background: $palette-neutral-1200;
    transform: scale(1.05);
  }

  &:active:not(.assistant__send-button--disabled) {
    transform: scale(0.95);
  }

  &--disabled {
    background: $palette-neutral-600;
    cursor: not-allowed;

    i {
      color: white;
    }
  }
}

// Message list

.assistant__messages-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.assistant__typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;

  span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: $palette-neutral-800;
    animation: assistant-typing-bounce 1.4s infinite ease-in-out;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }

    &:nth-child(2) {
      animation-delay: -0.16s;
    }
  }
}

@keyframes assistant-typing-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.assistant__message {
  display: flex;

  &--human {
    justify-content: flex-end;
  }

  &--ai {
    justify-content: flex-start;
  }
}

.assistant__message-content {
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;

  .assistant__message--human & {
    align-items: flex-end;
  }

  .assistant__message--ai & {
    align-items: flex-start;
  }
}

.assistant__message-text-container {
  display: flex;
  gap: 12px;
}

.assistant__message-bubble {
  background-color: $white;
  border: 1px solid $palette-neutral-200;
  border-radius: 12px;
  padding: 12px 16px;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  min-width: 0;

  & span.loading {
    margin-top: 4px;
  }

  .assistant__message--human & {
    background-color: $palette-neutral-100;
    border-color: $palette-neutral-100;
  }

  .assistant__message--error & {
    background-color: $palette-red-200;
  }

  .assistant__message--reasoning & {
    color: #16829c;
    background-color: $palette-cyan-50;
    border-color: $palette-cyan-50;
  }
}

.assistant__message-text {
  font-size: 13px;
  line-height: 20px;
  margin: 0;
  padding: 0;
  width: 100%;
  text-align: left;
  display: block;
  text-indent: 0;
  border: 0;
  outline: 0;

  // Markdown styles
  p {
    margin: 0 0 8px;
    color: $palette-neutral-1200;

    &:last-child {
      margin-bottom: 0;
    }
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin: 12px 0 8px;
    font-weight: 600;
    line-height: 1.3;
    color: $palette-neutral-1200;
  }

  h1 {
    font-size: 1.5em;
  }

  h2 {
    font-size: 1.3em;
  }

  h3 {
    font-size: 1.15em;
  }

  h4 {
    font-size: 1em;
  }

  h5 {
    font-size: 0.95em;
  }

  h6 {
    font-size: 0.9em;
  }

  h1:first-child,
  h2:first-child,
  h3:first-child,
  h4:first-child,
  h5:first-child,
  h6:first-child {
    margin-top: 0;
  }

  ul,
  ol {
    margin: 8px 0;
    padding-left: 20px;
    color: $palette-neutral-1200;
  }

  li {
    margin: 4px 0;
    line-height: 1.5;
    color: $palette-neutral-1200;
  }

  code {
    background-color: $palette-neutral-100;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: Monaco, 'Courier New', monospace;
    font-size: 0.9em;
  }

  pre {
    background-color: $palette-neutral-100;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;

    code {
      background-color: transparent;
      padding: 0;
      font-size: 0.85em;
    }
  }

  blockquote {
    border-left: 3px solid $palette-blue-200;
    padding-left: 12px;
    margin: 8px 0;
    color: $palette-neutral-800;
  }

  a {
    color: $palette-blue-500;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }
  }

  strong {
    font-weight: 600;
  }

  em {
    font-style: italic;
  }

  hr {
    border: none;
    border-top: 1px solid $palette-neutral-400;
    margin: 12px 0;
  }

  table {
    @extend %scrollbar-thin;

    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    overflow-x: auto;
    display: block;

    th,
    td {
      border: 1px solid $palette-neutral-400;
      padding: 8px;
      text-align: left;
      min-width: 80px;
      white-space: nowrap;
    }

    th {
      background-color: $palette-neutral-100;
      font-weight: 600;
    }
  }

  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: wrap;

  // Remove any inherited spacing
  &::before,
  &::after {
    content: none;
  }

  .assistant__message--human & code {
    background-color: rgba(255, 255, 255, 0.2);
  }
}

.assistant__reasoning-indicator {
  @include loading-spinner(#16829c, 14px);

  display: inline-block;
  margin-right: 8px;
  vertical-align: middle;
}

.assistant__chat-history-spacer {
  width: 300px;
}

// Sources section styles
.assistant__sources-section {
  margin-top: 12px;
  border-top: 1px solid $palette-neutral-200;
  padding-top: 8px;
}

.assistant__sources-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: $palette-neutral-700;
  width: 100%;
  transition: all 0.2s ease;

  &:hover {
    background-color: $palette-neutral-50;
    color: $palette-neutral-800;
  }
}

.assistant__sources-icon {
  font-size: 14px;
  color: $palette-neutral-700;
}

.assistant__sources-label {
  flex: 1;
  text-align: left;
  font-weight: 500;
}

.assistant__sources-chevron {
  font-size: 12px;

  &--expanded {
    transform: rotate(180deg);
  }
}

.assistant__sources-list {
  overflow: hidden;
  margin-top: 8px;
}

@keyframes slide-down {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.assistant__source-item {
  margin-bottom: 6px;

  &:last-child {
    margin-bottom: 0;
  }
}

.assistant__source-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background-color: $palette-neutral-100;
  border: 1px solid $palette-neutral-300;
  border-radius: 4px;
  text-decoration: none;
  color: $palette-neutral-900;
  font-size: 12px;

  &:hover {
    background-color: $palette-neutral-200;
    border-color: $palette-neutral-400;
    color: $palette-blue-700;
  }
}

.assistant__source-link-icon {
  font-size: 12px;
  color: $palette-neutral-700;
  flex-shrink: 0;
}

.assistant__source-url {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assistant__source-external-icon {
  font-size: 10px;
  color: $palette-neutral-400;
  flex-shrink: 0;
}

.assistant__actions {
  margin-top: 4px;
  width: 100%;
}

.assistant__actions-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

// Feedback buttons (inline in header)
.assistant__feedback-button {
  padding: 3px 6px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: $palette-neutral-500;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;

  i {
    font-size: 13px;
  }

  &:hover {
    color: $palette-neutral-700;
  }

  &--active {
    color: $palette-neutral-1200;
  }
}

// Feedback Context (popup near thumb down)
.assistant__feedback-context {
  min-width: 280px;

  textarea {
    width: 100%;
    min-height: 52px;
    resize: vertical;
  }
}

.assistant__feedback-context-content {
  padding: 12px;
}

.assistant__feedback-context-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.assistant__disclaimer {
  margin-top: 8px;
  margin-left: 8px;
  font-size: 11px;
  color: $palette-neutral-600;
  text-align: left;
  line-height: 1.4;
}

.assistant__send-button-icon-stop {
  background-color: white;
  transform: scale(0.7);
}
